package com.bianguo.android.functiondemo.retrofit;

import com.bianguo.android.functiondemo.bean.BaseEntity;
import com.bianguo.android.functiondemo.bean.UserBean;

import java.util.ArrayList;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;

public interface ApiService {

    @GET("top250")
    Observable<ResponseBody> getTopMovie(@Query("page") int page);

    @GET("servlet/FirstServlet")
    Observable<ResponseBody> getWebServletDemoData(@Query("page") int page);

    @FormUrlEncoded
    @POST("servlet/LoginServlet")
    Observable<BaseEntity<UserBean>> login(@Field("phoneNumber") String username, @Field("password") String password);

    @FormUrlEncoded
    @POST("servlet/RegisterServlet")
    Observable<BaseEntity<UserBean>> register(@Field("phoneNumber") String username, @Field("password") String password);

    @FormUrlEncoded
    @POST("user/save")
    Observable<BaseEntity<UserBean>> saveUser(@Field("name") String name);

    @Headers({
            "content-type: application/json"
    })
    @POST("user/save")
    Observable<BaseEntity<UserBean>> saveUser(@Body Map<String, String> params);

    @GET("person/find/all")
    Observable<BaseEntity<ArrayList<UserBean>>> getUsers();

    @Headers({
            "content-type: application/json"
    })
    @POST("user/find/user/by/id")
    Observable<BaseEntity<UserBean>> getUserById(@Body Map<String, Integer> params);
}
